package cn.itcasa.config;
import cn.itcasa.mqconstants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    /**
     * 交换机
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(MqConstants.ITEM_EXCHANGE, true, false);
    }
    @Bean
    public Queue insterQueue(){
        return new Queue(MqConstants.ITEM_INSERT_QUEUE, true);
    }
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstants.ITEM_DELETE_QUEUE, true);
    }
    /**
     * 声明绑定关系（新增修改队列）
     */
    @Bean
    public Binding insterBinding() {
        return BindingBuilder.bind(insterQueue()).to(topicExchange()).with(MqConstants.ITEM_INSERT_ROUTING_KEY);
    }
    /**
     * 声明绑定关系（删除队列）
     */
    @Bean
    public Binding deleteBinding() {
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.ITEM_DELETE_ROUTING_KEY);
    }
}
